/***************************************************************************
创建者：华磊
 开始时间：               : 2020.1１.09
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   顶部视窗对话框
*                                                                         *
 ***************************************************************************/
#include "changespeed.h"
#include "ui_changespeed.h"
#include "topview.h"
#include <QDebug>

ChangeSpeed::ChangeSpeed(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChangeSpeed)
{
    ui->setupUi(this);

    //初始化防空值
    beforeAutoSpeed = 0;
    beforeMaunalSpeed = 0;

    ui->lineEdit->setFocusPolicy(Qt::NoFocus);
    ui->lineEdit_2->setFocusPolicy(Qt::NoFocus);

    ui->horizontalSlider->setMinimum(2);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider_2->setMinimum(2);
    ui->horizontalSlider_2->setMaximum(100);

    setGeometry(rect().x()+200, rect().y()+50,450, 150);
    setAttribute(Qt::WA_QuitOnClose, false);


}

ChangeSpeed::~ChangeSpeed()
{
    delete ui;
}


void ChangeSpeed::on_changeprogramadd_clicked()
{
    emit changeAutoSpeed();
}

void ChangeSpeed::on_changeprogramreduce_clicked()
{
    emit reduceAutoSpeed();
}

void ChangeSpeed::on_changemanualadd_clicked()
{
    emit changeMaunalSpeed();
}

void ChangeSpeed::on_changemanualreduce_clicked()
{
    emit reduceMaunalSpeed();
}

//void ChangeSpeed::on_horizontalSlider_sliderMoved(int position)//移动
//{
//    QString number=QString::number(position);
//    ui->lineEdit->setText(number);

//}

//void ChangeSpeed::on_horizontalSlider_2_sliderMoved(int position)//移动
//{
//    QString number =QString::number(position);
//    ui->lineEdit_2->setText(number);

//}

//void ChangeSpeed::on_horizontalSlider_sliderReleased()//松开
//{
//    emit sliderAutoSpeed(QString::number(ui->horizontalSlider->sliderPosition()).toInt());

//    beforeAutoSpeed = QString::number(ui->horizontalSlider->sliderPosition()).toInt();
//}

//void ChangeSpeed::on_horizontalSlider_2_sliderReleased()//松开
//{
//    emit sliderMaunalSpeed(QString::number(ui->horizontalSlider_2->sliderPosition()).toInt());

//    beforeMaunalSpeed = QString::number(ui->horizontalSlider_2->sliderPosition()).toInt();
//}

void ChangeSpeed::on_horizontalSlider_valueChanged(int value)
{
//    ui->lineEdit->setText(QString::number(value));
//    //qDebug()<<"value-beforeAutoSpeed = "<<value-beforeAutoSpeed;
//    if((value-(int)beforeAutoSpeed)%10 == 0 || ((int)beforeAutoSpeed-value)%10 == 0)
//    {
        emit sliderAutoSpeed(value);

//        beforeAutoSpeed = value;
//    }
}

void ChangeSpeed::on_horizontalSlider_2_valueChanged(int value)
{
//    ui->lineEdit_2->setText(QString::number(value));
//    if((value-(int)beforeMaunalSpeed)%10 == 0 || ((int)beforeMaunalSpeed-value)%10 == 0)
//    {
        emit sliderMaunalSpeed(value);

//        beforeMaunalSpeed = value;
//    }
}

//更新数据

void ChangeSpeed::updateAutoAdd()
{
    if(beforeAutoSpeed != topView->autoSpeed)
    {

        QString number;
        if(topView->autoSpeed<2)
        {
            number = QString::number(topView->autoSpeed,'f',1);
        }
        else
        {
            number = QString::number(topView->autoSpeed);
        }

        ui->lineEdit->setText(number);
        ui->horizontalSlider->setSliderPosition(topView->autoSpeed);
        //topView->updateChangeSpeedView();

        //记录当前自动速度
        beforeAutoSpeed = topView->autoSpeed;
    }
}

void ChangeSpeed::updateMaunalAdd()
{
    if(beforeMaunalSpeed != topView->maunalSpeed)
    {
        QString number;
        if(topView->maunalSpeed<2)
        {
            number = QString::number(topView->maunalSpeed,'f',1);
        }
        else
        {
            number = QString::number(topView->maunalSpeed);
        }


        ui->lineEdit_2->setText(number);
        ui->horizontalSlider_2->setSliderPosition(topView->maunalSpeed);
        //topView->updateChangeSpeedView();

        //记录当前手动速度
        beforeMaunalSpeed = topView->maunalSpeed;
    }
}

void ChangeSpeed::changeLanguage()
{
    ui->retranslateUi(this);
}
